package com.neuedu.corejava.ch9;

public class StringClass {

	public static void main(String[] args) {
		
		String s=new String("abc");
		
		//java的字符串对象是不可以修改的，每次修改字符串都会分配新的内存空间
		//String类的修改性能很低，
		s=new String ("sfdzfzgthyjukiloplyutre");
		s=new String ("addsdffd");
		s=new String ("addsdffd1");
		
		//带缓冲的字符串类 --- StringBuffer线程安全;StringBuilder是多线程不安全
		//简述String ，StringBuffer和StringBuilder的异同
		StringBuilder buffer=new StringBuilder();
		//aStringBuffer buffer=new StringBuffer();
		buffer.append(false);//5
		buffer.append("Hello"); //5
		buffer.insert(5, "ABCDEF");//6
		
		int cap=buffer.capacity(); //字符串缓冲的容量
		int len=buffer.length(); //数据的长度
		
		System.out.println("=====================================");
		System.out.println(cap+","+len); 
		System.out.println(buffer.toString());
		System.out.println("=====================================");
	   
		buffer.insert(0, "A");//6
		cap=buffer.capacity();//字符串缓冲的容量
		len=buffer.length(); //数据的长度
		System.out.println(cap+","+len); 
		System.out.println(buffer.toString());
		System.out.println("=====================================");
		
		//buffer.deleteCharAt(0);
		//buffer.delete(0, 12);
		buffer.trimToSize();//释放没有使用的空间容量
		
		cap=buffer.capacity();//字符串缓冲的容量
		len=buffer.length(); //数据的长度
		System.out.println(cap+","+len); 
		System.out.println(buffer.toString());
		System.out.println("=====================================");
		
		buffer.replace(0, 1, "Q");
		buffer=buffer.reverse(); //字符串反向输出
		System.out.println(buffer.toString());
		System.out.println("=====================================");
		
		

		
		
		
		
		
	}

}
